// <editor-fold defaultstate="collapsed" desc="GNU GPLv3 Header">
/*
 * File:   WaveFormatNonPCM.java
 *
 * Copyright (C) 2013 Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * Copyright (C) 2013 David Megias Jimenez <dmegias@uoc.edu>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// </editor-fold>
package uoc.libwave;

import java.io.IOException;
import java.util.List;

/**
 * Class for storing a generic Non-PCM WAVE file format and, for reading and
 * writing its content in Data I/O Streams.
 *
 * @author Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * @version 1.0
 * @since 2013-08-27
 */
abstract class WaveFormatNonPCM<T> extends WaveFormat {

    /**
     * WAVE Format Chunk
     */
    ChunkFormatNonPCM chunkFormatNonPCM;
    /**
     * WAVE Fact Chunck
     */
    ChunkFact chunkFact;

    /**
     * 
     * @since 2013-08-27
     */
    public WaveFormatNonPCM() {
    }

    /**
     * 
     * @param HeaderChunkID
     * @param HeaderChunkSize
     * @param HeaderRiffType
     * @param FormatChunkID
     * @param FormatChunkSize
     * @param wFormatTag
     * @param wChannels
     * @param dwSamplesPerSec
     * @param dwAvgBytesPerSec
     * @param wBlockAlign
     * @param wBitsPerSample
     * @param cbSize
     * @param FactChunkID
     * @param FactChunkSize
     * @param dwSampleLength
     * 
     * @since 2013-08-31
     */
    WaveFormatNonPCM(String HeaderChunkID, int HeaderChunkSize,
            String HeaderRiffType, String FormatChunkID, int FormatChunkSize,
            short wFormatTag, short wChannels, int dwSamplesPerSec,
            int dwAvgBytesPerSec, short wBlockAlign, short wBitsPerSample,
            short cbSize, String FactChunkID, int FactChunkSize,
            int dwSampleLength) {
        super(HeaderChunkID, HeaderChunkSize, HeaderRiffType);
        chunkFormatNonPCM = new ChunkFormatNonPCM(FormatChunkID, FormatChunkSize,
                wFormatTag, wChannels, dwSamplesPerSec, dwAvgBytesPerSec,
                wBlockAlign, wBitsPerSample, cbSize);
        chunkFact = new ChunkFact(FactChunkID, FactChunkSize, dwSampleLength);
    }

    /**
     * 
     * @since 2013-08-31
     */
    WaveFormatNonPCM(int MasterChunkSize, short wFormatTag, short wChannel,
            int dwSamplesPerSec, int nAvgBytesPerSec, short nBlockAlign,
            short wBitsPerSample, int dwSampleLength) {
        super(MasterChunkSize);
        chunkFormatNonPCM = new ChunkFormatNonPCM(wFormatTag, wChannel,
                dwSamplesPerSec, nAvgBytesPerSec, nBlockAlign, wBitsPerSample);
        chunkFact = new ChunkFact(dwSampleLength);
    }

    /**
     *
     * @return
     *
     * @since 2013-08-27
     */
    public abstract T getMaxSample();

    /**
     *
     * @param wChannel
     * @param i
     * @return
     *
     * @since 2013-08-27
     */
    public abstract T getSample(short wChannel, int i);

    /**
     *
     * @param wChannel
     * @param i
     * @param value
     *
     * @since 2013-08-27
     */
    public abstract void setSample(short wChannel, int i, T value);

    /**
     *
     * @param start
     * @param size
     * @param _Channel
     * @param lframe
     *
     * @since 2013-08-27
     */
    public abstract void getFrame(int start, int size, short _Channel, List<T> lframe);

    /**
     *
     * @param start
     * @param lframe
     * @param _Channel
     *
     * @since 2013-08-27
     */
    public abstract void setFrame(int start, List<T> lframe, short _Channel);

    /**
     *
     * @param strDstFilePath
     *
     * @since 2013-08-27
     */
    public abstract void saveToFile(String strDstFilePath) throws IOException;

    /**
     *
     * @return
     * @since 2013-08-31
     */
    public int getDwSamplesPerSec() {
        return chunkFormatNonPCM.getDwSamplesPerSec();
    }

    /**
     *
     * @return
     *
     * @since 2013-09-01
     */
    public short getWChannel() {
        return chunkFormatNonPCM.getWChannels();
    }
}
